package com.dhl.single;

import javax.lang.model.element.VariableElement;

/**
 * @title: 饿汉式静态代码块
 * @Author danghailiang
 * @Date: 2022/7/26 20:33
 * @Version 1.0
 */
public class 饿汉式静态代码块 {
    public static void main(String[] args) {
        SingleStaticCode instance = SingleStaticCode.getInstance();
        SingleStaticCode instance1 = SingleStaticCode.getInstance();
        System.out.println(instance1 == instance);
    }
}

class SingleStaticCode{
    /**
     * 构造器私有化
     */
    private SingleStaticCode() {

    }
    /**
     * 创建静态变量
     */
    private static SingleStaticCode instance;
    /**
     * 静态代码块实例化对象
     */
    static {
        instance = new SingleStaticCode();
    }
    /**
     * 返回对象
     */
    public static SingleStaticCode getInstance() {
        return instance;
    }
}
